﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UploadImage.aspx.cs" Inherits="SCFHS.Shared.UploadImage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../Style/Main/Shared.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var cellTemplates = new Array();
        cellTemplates[0] = 'إختر الملف :';
        cellTemplates[1] = '<input id="file{counter}" name="file{counter}" type="file" />';
        cellTemplates[2] = 'الوصف : ';
        cellTemplates[3] = '<input id="txtDescription{counter}" name="txtDescription{counter}" type="text" value="" />';
        cellTemplates[4] = '<a href="#" id="lnkRemoveFile{counter}" onclick="return removeFile(this);">حذف</a>';

        $(document).ready(function () {
            if ($("#fileCounter").val() == "-1") {
                AppendNewFileItem(0);
            }
        });

        function AppendNewFileItem(count) {
            var newItem = $("#fileItem" + count);
            var IsNew = false;
            if (newItem.length == 0) {
                var fileItemClass = 'row fileItem';
                if (parseInt(count) % 2 != 0)
                    fileItemClass = 'row fileItem Alter';
                var template = $(".fileSelect").find("#fileItem0").get(0).innerHTML;
                newItem = '<div id="fileItem' + count + '" class="' + fileItemClass + '">' + template + "</div>";
                $(newItem).appendTo(".fileSelect");
                IsNew = true;
            }
            newItem = $("#fileItem" + count);
            $(newItem).find(".title").get(0).innerText = cellTemplates[0];
            //            $($(newItem).find(".file").get(0)).html(cellTemplates[1].replace(/\{counter\}/g, count));
            $(newItem).find(".file").get(0).innerHTML = cellTemplates[1].replace(/\{counter\}/g, count);
            $(newItem).find(".title").get(1).innerText = cellTemplates[2];
            $(newItem).find(".fileDescription").get(0).innerHTML = cellTemplates[3].replace(/\{counter\}/g, count);
            $(newItem).find(".deleteFile").get(0).innerHTML = cellTemplates[4].replace(/\{counter\}/g, count);

            var newCount = parseInt(count) + 1;
            $("#fileCounter").val(newCount);
            if (IsNew) {

            }

        }
        function addfile() {
            AppendNewFileItem($("#fileCounter").val());
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="pnlUpload" class="uploadContainer" runat="server">
        <div class="fileSelect">
            <input type="hidden" id="fileCounter" value="-1" name="fileCount" />
            <div id="fileItem0" class="row fileItem">
                <div class="title">
                </div>
                <div class="file">
                </div>
                <div class="title">
                </div>
                <div class="fileDescription">
                </div>
                <div class="deleteFile">
                </div>
            </div>
        </div>
        <div class="addfile">
            <a href="#" onclick="return addfile();">إضافة ملف آخر</a>
        </div>
        <center>
            <asp:Button Text="رفع الملفات" runat="server" ID="btnUpload" OnClick="btnUpload_Click"
                Width="200px" />
        </center>
    </div>
    </form>
</body>
</html>
